<%--
  Created by IntelliJ IDEA.
  User: ddd
  Date: 2018/4/19
  Time: 16:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加省份</title>
    <link href="${pageContext.request.contextPath}/static/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/bootstrap-datetimepicker.min.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/admin.css">
</head>
<body>
<div style="padding: 15px;">
    <form id="fo" class="bs-example bs-example-form" role="form" method='post' enctype="multipart/form-data">
        <div class="input-group">
            <span class="input-group-addon">省份</span>
            <input type="text" name="name" placeholder="请输入省份名" class="form-control">
        </div>
        <input type="hidden" name="type" class="form-control" value="1">
        <input type="hidden" name="parent" class="form-control" value="0">
        <br>
        <button class="btn btn-primary btn-lg btn-block validForm" type="button">提交保存</button>
    </form>
</div>

<script src="${pageContext.request.contextPath}/static/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/static/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/static/layer/layer.js"></script>
<script>
    $(".validForm").click(function () {
        var name = $("input[name='name']").val();
        var data;
        if (!name){
            layer.msg('请输入省份名',{icon : 2,time:1000});
            $("input[name='name']").focus();
            return false;
        }
        data = {name:name};
        $.ajax({
            type: 'POST',
            url: "/area",
            data: data,
            dataType: 'json',
            success: function (json) {
                if (json.status == "success") {
                    layer.msg('添加成功', {icon: 1, time: 1000});
                    setTimeout(function () {
                        parent.location.reload();
                    }, 1000);
                }
            },
            error: function () {
                layer.msg('服务器繁忙，请刷新页面后重试', {icon: 5, time: 1000});
            }
        });
    });

</script>
</body>
</html>
